/**
 * @purpose 业务服务接口基础实现
 * @author daizs
 * @created Feb 9, 2010
 */
package platform.common.service.impl;
import org.apache.log4j.Logger;

import platform.common.dao.IDomainProvider;
import platform.common.dao.IDomainProviderSet;
import platform.common.dao.impl.CriticalTechnicalDaoException;
import platform.common.dao.impl.DaoConfigException;
import platform.common.dao.impl.DaoException;
import platform.common.dao.impl.TechnicalDaoException;
import platform.common.exception.BusinessException;
import platform.common.exception.CriticalTechnicalException;
import platform.common.exception.InValidDataException;
import platform.common.exception.TechnicalException;
import platform.common.service.IBusinessService;
import platform.factory.ServiceLocator;
import platform.util.Util;



public class BaseBizServiceImpl implements IBusinessService{
	public Logger log = Logger.getLogger(this.getClass());
	/**
	 * 
	* 方法功能描述:验证id
	@param id
	* @author guotingting
	 * @throws BusinessException 
	* @created date  May 26, 2010
	 */
	public void checkId(String id) throws BusinessException{
		if (Util.isNull(id)) {
			throw  handleBusinessServiceException(new BusinessException("id为空"));
		}
	}
	/**
	 * 
	* 方法功能描述:验证对象是否为空
	@param id
	* @author guotingting
	 * @throws BusinessException 
	* @created date  May 26, 2010
	 */
	public void checkObject(Object o) throws BusinessException{
		if (Util.isNull(o)) {
			throw  handleBusinessServiceException(new BusinessException("对象为空"));
		}
	}
	/**
     * 领域对象提供者集合
     */
	protected IDomainProviderSet domainProviderSet;
	
	public IDomainProvider domainProvider;

	/**
     * @see platform.common.service.IBusinessService#getDomainProviderSet()
     */
	public IDomainProviderSet getDomainProviderSet() {
		return domainProviderSet;
	}

	/**
     * @see platform.common.service.IBusinessService#setDomainProviderSet(IDomainProviderSet)
     */
	public void setDomainProviderSet(IDomainProviderSet domainProviderSet) {
		this.domainProviderSet=domainProviderSet;
	}

	/* (non-Javadoc)
	 * @see platform.common.service.IBusinessService#handleBusinessServiceException(java.lang.Exception, java.lang.String)
	 */
	public BusinessException handleBusinessServiceException(String errMsg, Exception e) {
		if(e instanceof CriticalTechnicalDaoException) {
			return new CriticalTechnicalException(errMsg, e);
		} else if(e instanceof TechnicalDaoException) {
			return new TechnicalException(errMsg, e);
		} else if(e instanceof DaoConfigException) {
			return new CriticalTechnicalException(errMsg, e);
		} else if(e instanceof DaoException) {
			return new TechnicalException(errMsg, e);
		} else if(e instanceof DaoException) {
			return new TechnicalException(errMsg, e);
		} else if(e instanceof InValidDataException) {
			return (InValidDataException) e;
		} else if(e instanceof BusinessException) {
			return (BusinessException) e;
		} else {
			return new BusinessException(errMsg, e);
		}
	}

	/* (non-Javadoc)
	 * @see platform.common.service.IBusinessService#handleBusinessServiceException(java.lang.Exception)
	 */
	public BusinessException handleBusinessServiceException(Exception e) {
		return this.handleBusinessServiceException("", e);
	}
	
	public <T>T getDP(Class<T> c){
		return ServiceLocator.getService(c);
	}
	public IDomainProvider getDomainProvider() {
		return domainProvider;
	}
	public void setDomainProvider(IDomainProvider domainProvider) {
		this.domainProvider = domainProvider;
	}

}
